package com.xbs.controller.backstage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.CarManageEntity;
import com.xbs.service.selfdriving.CarManageService;
import com.xbs.utils.DateJsonValueProcessor;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

/**
 * 车辆管理
 * @author Administrator
 *
 */
@WebServlet("/backstage/carmanageservlet2")
public class CarManage2Servlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		CarManageService carManageservice = new CarManageService();
		List<CarManageEntity> carManagelist1 = carManageservice.select1();
		List<CarManageEntity> carManagelist2 = carManageservice.select2();
		JsonConfig jsonConfig = new JsonConfig();   
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);   
		jsonConfig.registerJsonBeanProcessor(java.sql.Date.class, new DateJsonValueProcessor());  
		jsonConfig.setExcludes(new String[]{"handler","hibernateLazyInitializer"}); 
		JSONArray jsonArray = JSONArray.fromObject(carManagelist1, jsonConfig);
		JSONArray jsonArray1 = JSONArray.fromObject(carManagelist2, jsonConfig);
		JSONObject jsonObj  = new JSONObject();
	    jsonObj.element("modelid", jsonArray);
	    jsonObj.element("storeid", jsonArray1);
		resp.getWriter().print(jsonObj.toString());
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String carid = req.getParameter("carid1");
		String modelid = req.getParameter("modelid");
		String type = req.getParameter("type1");
		int storeid = Integer.parseInt(req.getParameter("storeid"));
		CarManageService carManageservice = new CarManageService();
		carManageservice.insert1(carid, modelid, type, storeid);
		req.getRequestDispatcher("/backstage/selfDrivingcar").forward(req, resp);
	}
}
